package com.songcha.module_task.ui.fragment.task

import com.songcha.library_business.mvvm.BusinessRepository
import com.songcha.library_business.proxy.userinfo.UserInfoManager
import com.songcha.library_network.bean.BaseBean
import com.songcha.library_network.bean.BaseIntDataBean
import com.songcha.module_task.api.TaskApiManager
import com.songcha.module_task.bean.DailyTaskBean
import com.songcha.module_task.bean.SignDayNumberBean
import com.songcha.module_task.bean.SignTaskBean
import io.reactivex.Observable
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject

class TaskRepository:BusinessRepository() {
    fun getSignTask():Observable<SignTaskBean>{
        return TaskApiManager.api.getSignTask()
    }

    fun getUserSignDay():Observable<SignDayNumberBean>{
        return TaskApiManager.api.getUserSignDay()
    }

    fun completeTask(taskId:Int):Observable<BaseIntDataBean>{
        return TaskApiManager.api.completeTask(taskId)
    }

    fun getDailyTask():Observable<DailyTaskBean>{
        val json=JSONObject().apply {
            if(UserInfoManager.checkLogin())
                put("token",UserInfoManager.loginToken)
        }
        return TaskApiManager.api.getDailyTask(json.toString().toRequestBody())
    }

    fun sign():Observable<BaseBean>{
        return TaskApiManager.api.sign()
    }

}